import { PrismaClient } from "@prisma/client";
import { keyBy } from "lodash-es";
import { generate } from "./utils/generate";
import fs from "fs/promises";

const prisma = new PrismaClient();

async function main() {
  const user = await prisma.user.findMany({
    select: {
      userId: true,
      organId: true,
      sex: true,
      birthday: true,
      height: true,
      diplomas: true,
      maritalStatus: true,
      monthlySalaryType: true,
      houseProperty: true,
      vehicle: true,
      profession: true,
      vipEndTime: true,
      viewTimes: true,
    },
    where: {
      organId: 249,
      birthday: {
        not: null,
        gte: new Date("1900-01-01"), // 只查询有效日期
      },
    },
    take: 100,
  });

  console.log(user);

  // const field = await prisma.field.findMany({
  //   where: {
  //     organId: 249,
  //   },
  // });

  // //   根据fieldname转为对象使用lodash
  // const map = keyBy(field, "fieldname");

  // const result = user.map((item) => generate(map, item)).flat(2);

  // const stringify = JSON.stringify(result);

  // //   时间戳
  // const timestamp = Date.now();

  // await fs.writeFile(`./output/${timestamp}.jsonl`, stringify);
}

function arrayToJSONL(arr: any[]) {
  return arr.map((item) => JSON.stringify(item)).join("\n");
}

main();
